<template>
	<view class="container">
		<view class="navtop">
			<text>健康得分</text>
			<text style="font-size: 60px;color: #4CD964;">{{allnum}}</text>
			<text>{{checknum(allnum)}}</text>
		</view>
		<view class="myreport">
			<view class="reportbaogao">
				<text>健康</text><text>报告</text>
			</view>
			<view class="reportcontent">
				<text>{{text1}}</text>
			</view>
		</view>
		<view class="healthindex">
			<view class="function_1">
				<text>心率(次)</text>
				<text model="heartrate">{{heartrate}}</text>
				<text class="specialtext">{{show(heartrate)}}</text>
			</view>
			<view class="function_1">
				<text>血压(mmHg)</text>
				<text model="bloodpressure">{{bloodpressure_1}}/{{bloodpressure_2}}</text>
				<text class="specialtext">{{show1(bloodpressure_1,bloodpressure_2)}}</text>
			</view>
			<view class="function_1">
				<text>血糖(mmol)</text>
				<text model="bloodsugar">{{bloodsugar}}</text>
				<text class="specialtext">{{show2(bloodsugar)}}</text>
			</view>
			<view class="function_1">
				<text>血氧(%)</text>
				<text model="bloodoxygen">{{bloodoxygen}}</text>
				<text class="specialtext">{{show3(bloodoxygen)}}</text>
			</view>
			<view class="function_1">
				<text>血脂(mmol)</text>
				<text model="bloodfat">{{bloodfat}}</text>
				<text class="specialtext">{{show4(bloodfat)}}</text>
			</view>
			<view class="function_1">
				<text>膳食(cal)</text>
				<text model="diet">{{diet}}</text>
				<text class="specialtext">{{show5(diet)}}</text>
			</view>
		</view>
		<view class="pacecount">
			<view class="pacecounttop">
				<text>周步数统计</text>
			</view>
			<view class="pacecountbottom">
				<view class="count">
					<text>周均步数</text>
					<text>1973</text>
				</view>
				<view class="count">
					<text>周均距离/公里</text>
					<text>1.26</text>
				</view>
				<view class="count">
					<text>周均消耗/大卡</text>
					<text>71</text>
				</view>
			</view>
		</view>
		<view class="addcount">
			<button type="default" @click="addcon()">添加数据</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				text1: "改进膳食结构，均衡营养;摒弃不良生活习惯,戒烟限酒;合理安排生活工作,劳逸结合;制定定期疗养计划,避免长期超负荷工作;乐观向上，积极应对生活和工作压力；",
				heartrate: 50,
				bloodpressure_1: 120,
				bloodpressure_2: 80,
				bloodsugar: 12,
				bloodoxygen: 87,
				bloodfat: 3.8,
				diet: 600,
			}
		},
		methods: {
			//判断分数
			checknum(a) {
				if (a > 60) {
					return "身体状况良好"
				} else {
					return "身体状况较差"
				}
			},
			// 心率
			show(a) {
				if (a > 60 && a < 90) {
					return "正常"
				} else if (a <= 60) {
					return "较低";
				} else {
					return '偏高';
				}
			},
			// 血压
			show1(a, b) {
				if (90 <= a && a < 140 && 60 < b && b < 90) {
					return "正常"
				} else if (a < 90 || b < 60) {
					return "偏低"
				} else {
					return '偏高'
				}
			},
			//血糖
			show2(a) {
				if (3.9 < a && a < 6.1) {
					return "正常"
				} else if (a < 3.9) {
					return '偏低'
				} else {
					return '偏高'
				}
			},
			//血氧
			show3(a) {
				if (90 <= a && a < 96) {
					return "正常"
				} else if (a < 90) {
					return "偏低"
				} else {
					return '偏高'
				}
			},
			//血脂
			show4(a) {
				if (a < 2.6 && a > 1) {
					return "正常"
				} else if (a < 1) {
					return "偏低"
				} else {
					return '偏高'
				}
			},
			//膳食(按牛奶的量来算)
			show5(a) {
				if (350 < a && a < 500) {
					return "正常"
				} else if (a < 350) {
					return "偏低"
				} else {
					return '偏高'
				}
			},
			addcon() {
				uni.navigateTo({
					url: "./addhealthtexting"
				})
			},

			// 生命周期函数--监听页面

		},
		computed: {
			allnum: function() {
				let allnum = 100;
				//心率
				if (this.heartrate <= 60) {
					allnum = allnum - 2;
				} else if (this.heartrate > 90) {
					allnum = allnum - 10;
				};
				//血压
				if (this.bloodpressure_1 < 90 || this.bloodpressure_1 < 60) {
					allnum = allnum - 2;
				} else if (this.heartrate > 90) {
					allnum = allnum - 10;
				};
				//血糖
				if (this.bloodsugar < 3.9) {
					allnum = allnum - 5;
				} else if (this.bloodsugar > 6.1) {
					allnum = allnum - 10;
				};
				//血氧
				if (this.bloodoxygen < 90) {
					allnum = allnum - 15;
				} else if (this.bloodoxygen > 96) {
					allnum = allnum - 5;
				};
				//血脂
				if (this.bloodfat < 1) {
					allnum = allnum - 5;
				} else if (this.bloodfat > 2.6) {
					allnum = allnum - 10;
				};
				//膳食
				if (this.diet < 350) {
					allnum = allnum - 15;
				} else if (this.diet > 500) {
					allnum = allnum - 5;
				};
				return allnum;
			}
		},
		onLoad: function(option) {
			let that = this;
			const eventChannel = this.getOpenerEventChannel() // 兼容APP-NVUE

			// eventChannel.emit('someEvent', {data: 'test'});
			eventChannel.on('acceptDataFromOpenerPage', function(data) {
				console.log(data.data)
				that.heartrate = data.data.heartrate;
				that.bloodpressure_1 = data.data.bloodpressure_1;
				that.bloodpressure_2 = data.data.bloodpressure_2;
				that.bloodsugar = data.data.bloodsugar;
				that.bloodoxygen = data.data.bloodoxygen;
				that.bloodfat = data.data.bloodfat;
				that.diet = data.data.diet;
			})
		},
	}
</script>

<style>
	.container {
		width: 100%;
		padding: 0;
		font-size: 18px;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.navtop {
		color: #FFFFFF;
		width: 100%;
		height: 35%;
		background-color: #3774EC;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-around;
	}

	.myreport {
		width: 100%;
		height: 10%;
		font-size: 12px;
		display: flex;
		flex-direction: row;
		justify-content: space-evenly;
		align-items: center;
		border-bottom: 1px solid #dadada;
	}

	.reportbaogao {
		width: 50px;
		height: 50px;
		background-color: #3774EC;
		margin: 10px;
		color: #FFFFFF;
		font-size: 16px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.reportcontent {
		width: 70%;
		margin: 10px;
		height: 100%;
	}

	.healthindex {
		font-size: 14px;
		width: 90%;
		height: 100%;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-around;
	}

	.function_1 {
		width: 40%;
		height: 30%;
		margin-top: 5%;
		display: flex;
		flex-direction: column;
		align-items: center;
		border: 1px solid #dadada;
		padding: 5px;
		//box阴影
		box-shadow: 2px 2px 5px #b3b3b3;
	}

	.specialtext {
		color: #FFFFFF;
		text-align: center;
		width: 80px;
		height: 100%;
		background-color: #3774EC;
		border-radius: 10px;
	}

	.pacecount {
		margin-top: 5%;
		width: 100%;
		display: flex;
		flex-direction: column;
		text-align: center;
		font-size: 14px;
	}

	.pacecountbottom {
		widows: 90%;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}

	.count {
		width: 30%;
		display: flex;
		flex-direction: column;
	}

	.addcount {
		width: 100%;
		margin-top: 5%;
	}

	.addcount>button {
		color: #FFFFFF;
		width: 95%;
		background-color: #3774EC;
	}
</style>
